#ifndef _RPC_CONFMODULE_H_
#define _RPC_CONFMODULE_H_

#include "rpc_fwd.h"

#pragma once

class RPCConfModule : public AppModuleBase
{
public:
    typedef struct tgRPCServ{
        std::string     m_serv_full_name;
        int32_t         m_serv_id;
        std::string     m_serv_ip;
        int32_t         m_serv_port;
    }RPCServ;
    typedef List<RPCServ>   RPCServList;

public:
    RPCConfModule( RPCSysMgr * rpcsysmgr );
    virtual ~RPCConfModule() throw();
    virtual int32_t module_init();
    virtual void module_fini();
    virtual const char * module_name() const;
    static int32_t module_id();
    int32_t reload();

    inline const char * get_listen_ip() const {
        return m_listen_ip.c_str();
    }

    inline int32_t get_listen_port() const {
        return m_listen_port;
    }

    inline int32_t get_evt_queue_size() const {
        return m_evt_queue_size;
    }

    inline const RPCServList * get_rpcservlist() const {
        return &m_rpcserv_list;
    }

    inline const std::string & get_handshake_selfkey() const {
        return  m_handshake_selfkey;
    }

    inline int32_t get_heartbeat_interval() const {
        return m_heartbeat_interval;
    }

    inline int32_t get_heartbeat_timeout() const {
        return m_heartbeat_timeout;
    }

    inline int32_t get_handshake_interval() const {
        return m_handshake_interval;
    }

    inline int32_t get_channel_shmkey() const {
        return m_requestchannel_shmkey;
    }

    inline int32_t get_channel_shmsize() const {
        return m_requestchannel_shmsize;
    }

private:
    int32_t load_from_file();
    int32_t read_rpcbaseconf( TiXmlHandle & confighandle );
    //int32_t read_callstrategy( TiXmlHandle & confighandle );
    int32_t read_rpcservlist( TiXmlHandle & confighandle );
    void clear_rpcserv_list();
    void clear_callstrategy_arg();
    //int32_t get_callstrategy_val( const std::string & name );

private:
    RPCSysMgr *         m_rpcsysmgr;
    std::string         m_listen_ip;
    int32_t             m_listen_port;
    int32_t             m_evt_queue_size;
    std::string         m_handshake_selfkey;
    //CallStrategy **     m_callstrategy_ary;
    //int32_t             m_callstrategy_count;
    RPCServList         m_rpcserv_list;
    int32_t             m_heartbeat_interval;
    int32_t             m_heartbeat_timeout;
    int32_t             m_handshake_interval;
    // requestchannel
    int32_t             m_requestchannel_shmkey;
    int32_t             m_requestchannel_shmsize;
};

#endif // _RPC_CONFMODULE_H_

